from process import db_connect
from process import baseFunction as bf
import json
from fastapi import Query
from process.stockHq import PstockHq_closed, Pmootdx


def getStocksHq_closed(ts_codes: str = Query(...)) -> str:
    # 构造返回结果
    result_data = PstockHq_closed.stocksHq_closed(ts_codes)
    result = db_connect.R(code=200, success=True,
                          msg="Data fetched successfully", data=result_data)

    json_result = json.dumps(result, cls=bf.CustomEncoder)
    return json_result


def Cget_stocks_minute(tsCodeList: str = Query(...), tradeDate: str = Query(...)):
    result_data = Pmootdx.Pget_stocks_minutes(tsCodeList, tradeDate)
    # print(result_data)
    result = db_connect.R(code=200, success=True,
                          msg="Data fetched successfully", data=result_data)

    json_result = json.dumps(result, cls=bf.CustomEncoder)
    return json_result
